<template>
  <div class="height100 flex flex_d bg_fff" :class="is_close?'close_nav':''">
    <!-- <div class="common_tt flex_ac">
      <a href="javascript:;" @click="$router.go(-1)" class="back"><img src="@/assets/back.png" alt=""></a>
      <div class="title pad_lr20">编辑题目 <span style="font-size: 16px; display: none;">所属题库：题库模板1</span></div>
    </div> -->
    <div class="flex1 flex">

      <div class="flex1 page_div">
        <el-scrollbar class="page_div_scroll">
          <div class="flex">
            <div class="flex1">
              <div class="f16 pad_t20"><span class="color">题库列表 / 题库</span> / 编辑题目</div>
              <div class="pad_t10"><b>{{type_text[type] || '未知题型'}}</b></div>
              <el-form ref="form" :model="form" :rules="rules" label-position="top" v-loading="loading" class="pad_tb20 clearfix">
                <div class="clearfix" v-if="type!=3 && type!=4">
                  <el-form-item label="题干编辑" prop="title">
                    <editor keyname="title" ref="ue" :content="form.title"></editor>
                  </el-form-item>
                </div>

                <div class="clearfix tiankong_tt" style="position: relative;" v-if="type==3 || type==4">
                  <!-- v-if="answers.length==0" -->
                  <el-button type="primary" class="btns" size="medium" @click="add_zw" v-if="type==3" plain >插入填空占位符</el-button>
                  <el-form-item label="题干编辑" prop="title">
                    <editor keyname="title" ref="ue" :content="form.title" :is_tk='type==3?"1":"2"' @dele_item="ue_dele_item" @add_item="ue_add_item"></editor>
                  </el-form-item>
                </div>

                <el-form-item label="所属指标" prop="category_id">
                  <el-select v-model="form.category_id" placeholder="请选择" >
                    <el-option
                      v-for="item in categorys"
                      :key="item.id"
                      :label="item.title"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>


                <!-- <el-form-item label="打分要求" prop="notice">
                  <editor keyname="notice" ref="uenotice" :content="form.notice"></editor>
                </el-form-item> -->
                <el-form-item label="客户端备注" prop="kh_notice">
                  <el-input type="textarea" v-model="form.kh_notice"></el-input>
                  <!-- <editor keyname="kh_notice" ref="uekh_notice" :content="form.kh_notice"></editor> -->
                </el-form-item>


                <div class="clearfix" v-if="type==3 || type==4">
                  <el-form-item :label="type==3?'填空编辑':'描述编辑'" prop="have_answer">
                    <div class="subject_items">
                      <div class="item flex_ac" v-for="(item,index) in answers" :key="index">
                        <span class="zhuan_span" v-if="type==3">填空{{china_text[index]}}</span>
                        <div  class="flex1 pad_l10">
                          <el-input :value="item.answer_title" readonly style="width: 100%" placeholder="用户填空内容，初始状态的设置"></el-input>
                        </div>
                        <div class="flex_s flex_ac sub_op_btn">
                          <a href="javascript:;" class="margin_l20 color" @click="edit_item2(item,index)"><img src="@/assets/ans_edit.png" alt="">编辑</a>
                        </div>
                      </div>

                      <Nodata v-if="answers.length==0" text="暂无数据" />
                    </div>
                  </el-form-item>
                </div>

                <div class="clearfix" v-if="type==5 || type==6 || type==7">
                  <el-form-item label="矩阵题干编辑" prop="have_answer">
                    <div class="flex_ac pad_b10 pl">
                      <div class="margin_l20"><el-checkbox v-model="queschecked" @change="ques_check_all">全选</el-checkbox></div>
                      <div class="flex1 flex_ac pad_l20">
                        <!--不要 <el-button type="primary" size="medium" plain>复制到</el-button>
                        <el-button type="primary" size="medium" plain>移动到</el-button> -->
                        <el-button type="danger" size="medium" :disabled="ques_get_checked_indexs().length==0" @click="ques_handleDelete" plain>删除</el-button>
                        <el-button type="primary" size="medium" @click="edit_item3()">添加题干</el-button>
                      </div>
                    </div>
                    <div class="subject_items">
                      <div class="item flex_ac" v-for="(item,index) in ques" :key="index">
                        <div  class="flex1">
                          <el-checkbox v-model="item.is_check" @change="ques_check_item($event,index)"></el-checkbox><span class="margin_l10">{{index+1}}. {{item.answer_title}}</span>

                        </div>
                        <div class="flex_s flex_ac sub_op_btn">
                          <a href="javascript:;" class="margin_l20 color" @click="edit_item3(item,index)"><img src="@/assets/ans_edit.png" alt="">编辑</a>
                        </div>
                      </div>
                      <Nodata v-if="ques.length==0" />
                    </div>
                  </el-form-item>
                </div>

                <div class="clearfix" v-if="type==7 ">
                  <el-form-item label="选项编辑" prop="have_answer">
                    <div class="flex_ac pad_b10 pl">
                      <div class="margin_l20"><el-checkbox v-model="checked" @change="check_all">全选</el-checkbox></div>
                      <div class="flex1 flex_ac pad_l20">
                        <!--不要 <el-button type="primary" size="medium" plain>复制到</el-button>
                        <el-button type="primary" size="medium" plain>移动到</el-button> -->
                        <el-button type="danger" size="medium" :disabled="get_checked_indexs().length==0" @click="handleDelete" plain>删除</el-button>
                        <el-button type="primary" size="medium" @click="add_item">添加选项</el-button>
                      </div>
                    </div>
                    <div class="subject_items">
                      <div class="item flex_ac" v-for="(item,index) in answers" :key="index">
                        <div  class="flex1">
                          <el-checkbox v-model="item.is_check" @change="check_item($event,index)"></el-checkbox><span class="zhuan_span margin_l10">答案{{china_text[index]}}</span><span class="margin_l10">{{index+1}}. {{item.answer_title}}</span>
                          <span style="color: #FF9D00;">【{{item.score}}分】</span>
                        </div>
                        <div class="flex_s flex_ac sub_op_btn">
                          <!--不要 <a href="javascript:;" class="margin_l20 color"><img src="@/assets/answer2.png" alt="">分数设置</a> -->
                          <a href="javascript:;" class="margin_l20 color" @click="edit_item(item,index)"><img src="@/assets/ans_edit.png" alt="">编辑</a>

                        </div>
                      </div>
                      <Nodata v-if="answers.length==0" />
                    </div>
                  </el-form-item>
                </div>
                <div class="clearfix" v-if="type!=3 && type!=4 && type!=7 ">
                  <el-form-item label="选项编辑" prop="have_answer">
                    <div class="flex_ac pad_b10 pl">
                      <div class="margin_l20"><el-checkbox v-model="checked" @change="check_all">全选</el-checkbox></div>
                      <div class="flex1 flex_ac pad_l20">
                        <!--不要 <el-button type="primary" size="medium" plain>复制到</el-button>
                        <el-button type="primary" size="medium" plain>移动到</el-button> -->
                        <el-button type="danger" size="medium" :disabled="get_checked_indexs().length==0" @click="handleDelete" plain>删除</el-button>
                        <el-button type="primary" size="medium" @click="add_item">添加选项</el-button>
                      </div>
                    </div>
                    <div class="subject_items">
                      <div class="item flex_ac" v-for="(item,index) in answers" :key="index">
                        <div  class="flex1">
                          <el-checkbox v-model="item.is_check" @change="check_item($event,index)"></el-checkbox><span class="zhuan_span margin_l10">答案{{china_text[index]}}</span><span class="margin_l10">{{index+1}}. {{item.answer_title}}</span>
                          <span style="color: #FF9D00;">【{{item.score}}分】</span>
                        </div>
                        <div class="flex_s flex_ac sub_op_btn">
                          <a href="javascript:;" class="margin_l20 " :class="item.is_open==1?'color_green':'color'" @click="open_item(index)"><img v-if="item.is_open==0" src="@/assets/answer4.png" alt=""><img v-if="item.is_open==1" src="@/assets/answer4a.png" alt="">{{item.is_open==1?'已开放':'开放'}}</a>
                          <!--不要 <a href="javascript:;" class="margin_l20 color"><img src="@/assets/answer2.png" alt="">分数设置</a> -->
                          <a href="javascript:;" class="margin_l20 color" @click="edit_item(item,index)"><img src="@/assets/ans_edit.png" alt="">编辑</a>
                          <div class="flex_ac margin_l20 f16" v-if="type==2">
                            排他：<el-switch v-model="item.is_exclude" @change="exclude_chage($event,index)" class="margin_a"></el-switch>
                          </div>
                        </div>
                      </div>
                      <Nodata v-if="answers.length==0" />
                    </div>
                  </el-form-item>
                </div>


                <div class="clearfix">
                  <FormItem label="展示排序" type="input" :form="form" prop="kf_sort"  />
                </div>

              </el-form>

            </div>
            <!-- <rightset /> -->
            <div class="right_set pad_lr20 pad_tb20 margin_l40">
              <div class="f18"><b>题干设置</b></div>
              <template v-if="type==2">
                <div class="tt">最少选择</div>
                <div class="flex_ac setitem" style="padding-left: 0;">
                  <div class="flex1">
                    <el-input type="number" @blur="no_float('min_change')" :min="1" :step="1" placeholder="请填写" v-model="form.min_change" size="small"></el-input>
                  </div>
                  <div class="flex_s">个选项</div>
                </div>
                <div class="tt">最多选择</div>
                <div class="flex_ac setitem" style="padding-left: 0;">
                  <div class="flex1">
                    <el-input type="number" @blur="no_float('max_change')" :min="1" :step="1" placeholder="请填写" v-model="form.max_change" size="small"></el-input>
                  </div>
                  <div class="flex_s">个选项</div>
                </div>
                <div class="tt">选项顺序</div>
                <div class="flex_ac setitem" style="padding-left: 0;">
                  <div class="flex1">
                    <el-select v-model="form.order_type" placeholder="请选择"  size="small">
                      <el-option
                        v-for="item in order_types"
                        :key="parseInt(item.type)"
                        :label="item.title"
                        :value="parseInt(item.type)">
                      </el-option>
                    </el-select>
                  </div>
                </div>
              </template>
              <!-- <div class="tt">自动勾选</div>
              <div class="flex_ac setitem">
                <div class="flex1"><span class="dark">暂未设置</span></div>
                <a href="javascript:;" @click="open=true">去设置</a>
              </div>
              <div class="tt">跳转逻辑</div>
              <div class="flex_ac setitem">
                <div class="flex1">已设置2项</div>
                <a href="javascript:;" @click="open2=true">去设置</a>
              </div>
              <div class="line"></div> -->
              <div class="tt">上传附件</div>
              <div class=" pad_t20" style="justify-content: space-between;">
                <el-checkbox-group v-model="form.main_annex">
                    <el-checkbox label="1" style="margin-bottom: 10px; width: 100%;">图片</el-checkbox>
                    <el-checkbox label="2" style="margin-bottom: 10px; width: 100%;">视频</el-checkbox>
                    <el-checkbox label="3" style="margin-bottom: 10px; width: 100%;">文档</el-checkbox>
                    <el-checkbox label="4" style="margin-bottom: 10px; width: 100%;">压缩包</el-checkbox>
                  </el-checkbox-group>
              </div>
            </div>

          </div>
          <div style="padding-bottom: 60px;"></div>
        </el-scrollbar>

      </div>
    </div>

    <div class="fixed_submit_btn flex_ac_jc">
      <el-button type="primary" :loading="is_ajax" style="width: 100px;" @click="submitForm('form')">保存</el-button>
      <el-button style="width: 100px;" @click="$router.go(-1);">取消</el-button>
    </div>


    <el-dialog v-dialogDrag :close-on-click-modal="false" class="" :title="form2.answer_title" :visible.sync="open2" width="1000px" append-to-body>
      <el-form ref="form2" :model="form2" label-position="top" :rules="rules2" label-width="100px">
        <el-row>
          <FormItem label="选项内容" :span="24" type="textarea" :form="form2" prop="answer_title"  />
        </el-row>
        <el-row>
          <FormItem label="扣分描述" :span="24" type="textarea" :form="form2" prop="kf_desc"  />
        </el-row>
        <el-row :gutter="20">
          <FormItem label="分数设置" :span="10" type="number" :form="form2" prop="score"  />
          <el-col :span="10">
          	<el-form-item label="上传附件" prop="annex">
              <div class="flex_ac" style="justify-content: space-between;">
                <el-checkbox-group v-model="form2.annex">
                  <el-checkbox label="1">图片</el-checkbox>
                  <el-checkbox label="2">视频</el-checkbox>
                  <el-checkbox label="3">文档</el-checkbox>
                  <el-checkbox label="4">压缩包</el-checkbox>
                </el-checkbox-group>
              </div>
            </el-form-item>
          </el-col>

        </el-row>


        <el-row :gutter="20" v-if="form2.is_open==1">
          <FormItem label="规则设定" :span="10" type="select" :form="form2" prop="score_rule_id" :seleDatas="rule_types" seleKey="id" seleName="title" clearable />
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open2=false;">取 消</el-button>
        <el-button type="primary" @click="submitForm('form2')" :loading="is_ajax">{{is_ajax?'保存中···':'确定'}}</el-button>
      </div>
    </el-dialog>


    <el-dialog v-dialogDrag :close-on-click-modal="false" title="添加选项" :visible.sync="open3" width="1000px" append-to-body>
      <el-form ref="form4" :model="form4" label-position="top" :rules="rules4" label-width="100px">
        <el-row>
          <div style="position: relative;">
            <el-select v-model="ans_id" @change="ans_model_change" v-if="type!=7" placeholder="请选择" style="position: absolute; left: 100px; width: 600px; top: -7px;"  size="small">
              <el-option
                v-for="item in ans_model"
                :key="item.id"
                :label="item.title"
                :value="item.id">
              </el-option>
            </el-select>
            <FormItem label="选项内容" :placeholder="type==7?'请输入选项内容':'请输入选项内容(多个选项之间请以 ** 分割)'" :span="24" type="textarea" :form="form4" prop="answer_title"  />
          </div>
        </el-row>
        <el-row :gutter="20">
          <FormItem label="分数设置" :span="10" type="number" :form="form4" prop="score"  />
          <el-col :span="10">
          	<el-form-item label="上传附件" prop="annex">
              <div class="flex_ac" style="justify-content: space-between;">
                <el-checkbox-group v-model="form4.annex">
                  <el-checkbox label="1">图片</el-checkbox>
                  <el-checkbox label="2">视频</el-checkbox>
                  <el-checkbox label="3">文档</el-checkbox>
                  <el-checkbox label="4">压缩包</el-checkbox>
                </el-checkbox-group>
              </div>
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open3=false;">取 消</el-button>
        <el-button type="primary" @click="submitForm('form4')" :loading="is_ajax">{{is_ajax?'保存中···':'确定'}}</el-button>
      </div>
    </el-dialog>
    <el-dialog v-dialogDrag :close-on-click-modal="false" class=" hidett" title="编辑" :visible.sync="open4" width="500px" append-to-body>
      <el-form ref="form5" :model="form5" label-position="top" :rules="rules5" label-width="100px">
        <el-row>
          <FormItem label="题干内容" :span="24" type="textarea" :form="form5" prop="answer_title"  />
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open4=false;">取 消</el-button>
        <el-button type="primary" @click="submitForm('form5')" :loading="is_ajax">{{is_ajax?'保存中···':'确定'}}</el-button>
      </div>
    </el-dialog>
    <el-dialog v-dialogDrag :close-on-click-modal="false" class="" :title="type==3?'填空':'描述'" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form3" :model="form3" label-position="top" :rules="rules3" label-width="100px">
        <div class="f16 pad_b10" style="margin-top: -15px;"><b>{{type==3?'填空':'描述'}}设置</b></div>
        <el-row :gutter="10">
          <!-- <FormItem label="选项编号" :span="12" type="input" :form="form" prop="a"  /> -->
          <FormItem label="选项名称" :span="12" type="input" :form="form3" prop="answer_title"  />
          <FormItem label="扣分描述" :span="12" type="input" :form="form3" prop="kf_desc"  />
        </el-row>

        <!-- <el-row>
          <el-form-item label="填写内容" prop="file">
            <el-radio-group v-model="form.annex">
              <el-radio label="1">不限</el-radio>
              <el-radio label="2">文字、数字</el-radio>
              <el-radio label="3">联系方式</el-radio>
              <el-radio label="4">日期、时间</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-row> -->
        <el-row :gutter="20" v-if="type==4">
          <FormItem label="最小字数" :span="12" type="number" :form="form3" prop="min_num"  />
          <FormItem label="最大字数" :span="12" type="number" :form="form3" prop="max_num"  />
        </el-row>

        <!-- <el-row :gutter="20">
          <FormItem label="输入框宽度" :span="12" type="number" unit="字符" :form="form3" prop="rows"  />
          <FormItem label="输入框行数" :span="12" type="number" unit="行" :form="form3" prop="cols"  />
        </el-row> -->
        <!-- <div class="f16 pad_b10" style="margin-top: -15px;"><b>填空设置</b></div> -->
        <el-row :gutter="20">
          <FormItem label="分数设置" :span="12" type="number" :form="form3" prop="score"  />
          <el-col :span="12">
          	<el-form-item label="上传附件" prop="file">
              <div class="flex_ac" style="justify-content: space-between;">
                <el-checkbox-group v-model="form3.annex">
                  <el-checkbox label="1">图片</el-checkbox>
                  <el-checkbox label="2">视频</el-checkbox>
                  <el-checkbox label="3">文档</el-checkbox>
                  <el-checkbox label="4">压缩包</el-checkbox>
                </el-checkbox-group>
              </div>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <FormItem label="规则设定" :span="12" type="select" :form="form3" prop="score_rule_id" :seleDatas="rule_types" seleKey="id" seleName="title" clearable />
          <!-- <el-col :span="12">
            <el-form-item label="规则设定" prop="file">
              <div class="flex_ac">
                <el-select v-model="value" size="small" style="width: 118px; margin-right: 5px;" placeholder="选填">
                    <el-option
                      v-for="item in openOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                </el-select>
                <el-select v-model="value" size="small" style="width: 73px; margin-right: 5px;" placeholder="选填">
                    <el-option
                      v-for="item in openOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                </el-select>
                <div class="flex1">
                  <el-select v-model="value" size="small" style="width: 100%;" placeholder="选填">
                      <el-option
                        v-for="item in openOptions"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                  </el-select>
                </div>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结果设定" prop="file">
              <div class="flex_ac">
                <el-select v-model="value" size="small" style="width: 118px; margin-right: 5px;" placeholder="选填">
                    <el-option
                      v-for="item in openOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                </el-select>
                <el-input placeholder="0" type="number" size="small" style="width: 54px;"></el-input>
                <div style="padding: 0 5px;">=</div>
                <div class="flex1">
                  <el-select v-model="value" size="small" style="width: 100%;" placeholder="选填">
                      <el-option
                        v-for="item in openOptions"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                  </el-select>
                </div>
              </div>
            </el-form-item>
          </el-col> -->
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open=false;">取 消</el-button>
        <el-button type="primary" @click="submitForm('form3')" :loading="is_ajax">{{is_ajax?'保存中···':'确定'}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import rightset from "./right_set.vue";
import Editor from '@/components/BdEditor';
export default {
  name: 'addsub',
  // components: {rightset},
  components: {Editor},
  data () {
    return {
      is_ajax:false,
      loading:false,
      is_close:false,
      value:'',
      id:'',
      form: {
        main_annex:[]
      },
      // 表单校验
      rules: {
        // have_answer: [
        //   { required: true, message: "选项不能为空", trigger: "blur" }
        // ],
        title: [
          { required: true, message: "题干名称不能为空", trigger: "blur" }
        ],
        category_id: [
          { required: true, message: "所属指标不能为空", trigger: "blur" }
        ]
      },
      openOptions: [{label:'当前页面打开',value:1},{label:'新页面打开',value:2}],
      checked:false,
      open:false,
      open2:false,
      // 表单参数
      form2: {
        annex:[]
      },
      // 表单校验
      rules2: {
        score: [
          { required: true, message: "分数不能为空", trigger: "blur" }
        ],
        answer_title: [
          { required: true, message: "选项内容不能为空", trigger: "blur" }
        ]
      },

      // 表单参数
      form3: {
        annex:[]
      },
      // 表单校验
      rules3: {
        // score: [
        //   { required: true, message: "分数不能为空", trigger: "blur" }
        // ],
        answer_title: [
          { required: true, message: "选项名称不能为空", trigger: "blur" }
        ],
        // min_num: [
        //   { required: true, message: "最小字数不能为空", trigger: "blur" }
        // ],
        // max_num: [
        //   { required: true, message: "最大字数不能为空", trigger: "blur" }
        // ],
        // score_rule_id: [
        //   { required: true, message: "规则不能为空", trigger: "blur" }
        // ],
        // rows: [
        //   { required: true, message: "输入框宽度不能为空", trigger: "blur" }
        // ],
        // cols: [
        //   { required: true, message: "输入框行数不能为空", trigger: "blur" }
        // ]
      },
      open4:false,
      // 表单参数
      form5: {
        annex:[]
      },
      // 表单校验
      rules5: {
        // score: [
        //   { required: true, message: "分数不能为空", trigger: "blur" }
        // ],
        answer_title: [
          { required: true, message: "题干名称不能为空", trigger: "blur" }
        ],
        // min_num: [
        //   { required: true, message: "最小字数不能为空", trigger: "blur" }
        // ],
        // max_num: [
        //   { required: true, message: "最大字数不能为空", trigger: "blur" }
        // ],
        // score_rule_id: [
        //   { required: true, message: "规则不能为空", trigger: "blur" }
        // ],
        // rows: [
        //   { required: true, message: "输入框宽度不能为空", trigger: "blur" }
        // ],
        // cols: [
        //   { required: true, message: "输入框行数不能为空", trigger: "blur" }
        // ]
      },

      content:'',
      radio:'',
      type_text:{1:'单选题',2:'多选题',3:'填空题',4:'描述题',5:'矩阵单选题',6:'矩阵多选题',7:'矩阵填空题'},
      type:'', //题型
      modelid:''  ,//模板id,
      answers:[],
      china_text:['一','二','三','四','五','六','七','八','九','十'],
      order_types:[], //多选排序
      rule_types:[],
      ques:[],
      queschecked:false,
      open3:false,
      // 表单参数
      form4: {
        annex:[]
      },
      // 表单校验
      rules4: {
        score: [
          { required: true, message: "分数不能为空", trigger: "blur" }
        ],
        answer_title: [
          { required: true, message: "选项内容不能为空", trigger: "blur" }
        ]
      },
      all_ids:[],
      ans_id:'',
      categorys:[],
      ans_model:[{id:'1',title:'是**不是**不知道'},{id:'2',title:'能**不能**不知道'},{id:'3',title:'会**不会**不知道'},{id:'4',title:'重要**不重要**不知道'},{id:'5',title:'是**否'}]
    }
  },
  mounted() {
    this.id=this.$route.query.id || '';
    this.modelid=this.$route.query.modelid || '';
    this.type=this.$route.query.type || '';
    if(this.id){
      this.get_data()
    }else{
      let form_d={
        title:'',
        type:this.type,
        main_annex:[],
        q_id:this.modelid,
      }
      if(this.type==2){
        form_d.max_change=5;
        form_d.min_change=1;
        form_d.order_type='';
      }
      this.form=form_d;
      if(this.type==4){this.ue_add_item()}
    }
    this.get_options()
  },
  methods:{
    edit_item3(row,index){
      if(row){
        this.edit_index=index;
        this.form5={...row};
      }else{
        this.edit_index=-1;
        this.form5={is_check:false};
      }

      this.open4=true;
      this.resetForm('form5')
    },
    ques_handleDelete(row) {
      const _this=this;
      const indexs = this.ques_get_checked_indexs();
      const ids = this.ques_get_checked_ids();
      this.$confirm('是否确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
            if(ids.length>0){
              _this.axios.post('/api/subject.AnswerOperate/del_answer', {answer_ids:ids}).then(function(data) {
                if(data){
                  for(let i=indexs.length-1;i>=0;i--){
                    _this.ques.splice(indexs[i],1);
                    // _this.form.have_answer=_this.ques.length>0?1:'';
                    _this.$forceUpdate();
                  }
                }
              }).catch(function(error) {
                console.log(error);
              })
            }else{
              for(let i=indexs.length-1;i>=0;i--){
                _this.ques.splice(indexs[i],1);
                // _this.form.have_answer=_this.ques.length>0?1:'';
                _this.$forceUpdate();
              }
            }
        })
    },
    ques_get_checked_indexs(){
      let arr=[];
      for(let i=0;i<this.ques.length;i++){
        if(this.ques[i].is_check){
          arr.push(i)
        }
      }
      return arr
    },
    ques_get_checked_ids(){
      let arr=[];
      for(let i=0;i<this.ques.length;i++){
        if(this.ques[i].is_check && this.ques[i].id){
          arr.push(this.ques[i].id)
        }
      }
      return arr
    },
    ques_check_item(e,i){
      this.ques[i].is_check=e;
      if(this.ques_get_checked_indexs().length==this.ques.length && !this.ques.length==0){
        this.queschecked=true;
      }else{
        this.queschecked=false;
      }
      this.$forceUpdate();
    },

    ques_check_all(e){
      for(let i=0;i<this.ques.length;i++){
        this.ques[i].is_check=e
      }
    },
    ans_model_change(e){
      for(let i=0;i<this.ans_model.length;i++){
        if(e==this.ans_model[i].id){
          this.form4.answer_title=this.ans_model[i].title;
          break;
        }
      }
    },
    exclude_chage(){
      this.$forceUpdate()
    },
    get_options(){
      const _this=this;
      if(this.type==2){
        _this.axios.get("/api/Multiple/order_type_data", {params:{}}).then(function(res) {
          if(res){
            _this.order_types=res.message;
            if(!_this.id){
              _this.form.order_type=_this.order_types.length>0?parseInt(_this.order_types[0].type):''
            }
          }
        }).catch(function(error) {
          console.log(error);
        })
      }
      // if(this.type==3 || this.type==4){
        _this.axios.get("/api/Completion/calculate_result_data", {params:{}}).then(function(res) {
          if(res){
            let arr=res.message;
            for(let i=0;i<arr.length;i++){
              arr[i].id=parseInt(arr[i].id)
            }
            _this.rule_types=arr;
          }
        }).catch(function(error) {
          console.log(error);
        })
      // }


      _this.axios.get("/api/SubjectCategory/index", {params:{q_id:_this.modelid}}).then(function(res) {
        if(res){
          _this.categorys=res.message
        }
      }).catch(function(error) {
        console.log(error);
      })
    },
    no_float(key){
      if(parseInt(this.form[key])<1){
        this.form[key]=1
      }else{
        // if(parseInt(this.form[key])>this.answers.length){
        //   this.form[key]=this.answers.length
        // }else{
          this.form[key]=parseInt(this.form[key])
        // }
      }
    },
    open_item(i){
      console.log(i)
      this.answers[i].is_open=this.answers[i].is_open==1?0:1;
      this.$forceUpdate();
    },
    check_all(e){
      for(let i=0;i<this.answers.length;i++){
        this.answers[i].is_check=e
      }
    },
    get_checked_indexs(){
      let arr=[];
      for(let i=0;i<this.answers.length;i++){
        if(this.answers[i].is_check){
          arr.push(i)
        }
      }
      return arr
    },
    get_checked_ids(){
      let arr=[];
      for(let i=0;i<this.answers.length;i++){
        if(this.answers[i].is_check && this.answers[i].id){
          arr.push(this.answers[i].id)
        }
      }
      return arr
    },
    check_item(e,i){
      this.answers[i].is_check=e;
      if(this.get_checked_indexs().length==this.answers.length && !this.answers.length==0){
        this.checked=true;
      }else{
        this.checked=false;
      }
      this.$forceUpdate();
    },
    add_item(){

      this.open3=true;
      this.form4={
        annex:[],
        score:0,
        answer_title:'',
        min_num:1,
        max_num:50,
        kf_desc:''
      }
      this.resetForm('form4')
      // let obj={
      //   annex: [],
      //   answer_title: "答案内容",
      //   score:1,
      //   is_open: 0,
      //   is_check:false,
      //   is_exclude:false,
      // }
      // if(this.answers.length<10){
      //   this.answers.push(obj);
      // }
    },
    get_data(){
      const _this=this;
      let url='/api/subject.SubjectOperate/subject_info';
      // if(this.type==2){
      //   url='/api/Multiple/subject_info'
      // }
      // if(this.type==3 || this.type==4){
      //   url='/api/Completion/subject_info'
      // }
      _this.axios.get(url, {params:{id:_this.id}}).then(function(res) {
        if(res){
          _this.form=res.message;
          _this.form.main_annex=_this.form.main_annex==''?[]:_this.form.main_annex.split(',');
          _this.form.title=_this.add_upload_http(_this.form.title);
          // _this.form.notice=_this.add_upload_http(_this.form.notice || '')
          // _this.form.kh_notice=_this.add_upload_http(_this.form.kh_notice || '')
          let arr=res.message.answer || [];
          // _this.form.have_answer=arr.length>0?1:'';
          let all_ids=[];
          for(let i=0;i<arr.length;i++){
            all_ids.push(arr[i].id)
            arr[i].is_check=false;
            arr[i].is_exclude=arr[i].is_exclude==1?true:false;
            arr[i].annex=arr[i].annex==''?[]:arr[i].annex.split(',');
            arr[i].score_rule_id=arr[i].score_rule_id==0?'':arr[i].score_rule_id;
            if(_this.type==3 || _this.type==4){
              arr[i].cols=arr[i].completion_rule.cols;
              arr[i].max_num=arr[i].completion_rule.max_num;
              arr[i].min_num=arr[i].completion_rule.min_num;
              arr[i].rows=arr[i].completion_rule.rows;
            }
          }
          _this.all_ids=[...all_ids];
          _this.answers=arr;
          _this.ques=res.message.perform || [];
        }
      }).catch(function(error) {
        console.log(error);
      })
    },
    ue_dele_item(e){
      this.answers.splice(e,1);
      // this.form.have_answer=this.answers.length>0?1:'';
      // this.$forceUpdate();
    },
    ue_add_item(e,time){
      console.log('增加'+JSON.stringify(e));
      let obj={
        answer_title:'请输入',
        score:'0',
        min_num:1,
        max_num:50,
        rows:'',
        cols:'',
        score_rule_id:'',
        time:e?e.time:Date.now(),
        annex:[],
        kf_desc:''
      }
      if(this.type==3){
        this.answers.splice(e.i,0,obj)
      }
      if(this.type==4){
        this.answers.push(obj)
      }

    },
    add_zw(){
      console.log(this.form.title)
      this.$refs.ue.add_item('<span class="tk_line" data-time="'+Date.now()+'" style="user-select: none; display:inline-block; -webkit-user-modify: read-only;">________</span>')
    },
    edit_item2(row,index){
      this.edit_index=index;
      this.form3={...row};
      this.open=true
    },
    edit_item(row,index){
      this.edit_index=index;
      this.form2={...row};
      this.open2=true
    },
    submitForm(formName) {
      const _this=this;
      if(formName=='form'){
        this.form.title=this.remove_upload_http(this.$refs.ue.get_content());
        // this.form.notice=this.remove_upload_http(this.$refs.uenotice.get_content());
        // this.form.kh_notice=this.remove_upload_http(this.$refs.uekh_notice.get_content());
      }

      this.$refs[formName].validate((valid) => {
        if (valid) {
          if(formName=='form5'){
            if(this.edit_index==-1){
              this.ques.push({...this.form5});
            }else{
              this.ques[this.edit_index]={...this.form5};
            }

            this.$forceUpdate();
            this.open4=false;
          }
          if(formName=='form2'){
            this.answers[this.edit_index]={...this.form2};
            this.$forceUpdate();
            this.open2=false;
          }
          if(formName=='form3'){
            this.answers[this.edit_index]={...this.form3};
            this.$forceUpdate();
            this.open=false;
          }
          if(formName=='form4'){
            let arr=this.form4.answer_title.split('**');

            for(let i=0;i<arr.length;i++){
              let obj={
                annex: this.form4.annex,
                answer_title: arr[i],
                score:this.form4.score,
                is_open: 0,
                is_check:false,
                is_exclude:false
              }
              if(this.answers.length<10){
                this.answers.push(obj);
              }
            }
            this.open3=false;
          }
          if(formName=='form'){
            if(_this.ques.length==0 && (_this.type==5 || _this.type==6 || _this.type==7)){
              _this.tip_show('矩阵题干不能为空','error')
              return false;
            }
            if(_this.answers.length==0){
              _this.tip_show('选项不能为空','error')
              return false;
            }
            if(_this.type==3 || _this.type==4){
              for(let i=0;i<_this.answers.length;i++){
                if(_this.answers[i].answer_title==''){
                  _this.tip_show('请完善填空项','error')
                  return false;
                }
              }
            }

            _this.is_ajax=true;
            let _data={..._this.form};
            let del_ids=[..._this.all_ids];
            let answers=[..._this.answers]
            for(let i=0;i<answers.length;i++){
              answers[i].annex=answers[i].annex.join(',');
              if(_this.type==2){
                answers[i].is_exclude=answers[i].is_exclude?1:0
              }
              let d_index=del_ids.indexOf(answers[i].id)
              if(d_index!=-1){
                del_ids.splice(d_index,1)
              }
            }
            _data.main_annex=_data.main_annex.join(',');
            _data.answer_data=answers;
            _data.perform_data=[..._this.ques];

            _data.dele_ids=del_ids.join(',')
            console.log(_data);
            let url;
            url="/api/subject.SubjectOperate/edit_subject";
            if(!_this.id){url="/api/subject.SubjectOperate/add_subject";}
            // if(_this.type==1){
            //   url="/api/subject.SubjectOperate/edit_subject";
            //   if(!_this.id){url="/api/subject.SubjectOperate/add_subject";}
            // }
            // if(_this.type==2){
            //   url="/api/Multiple/edit_subject";
            //   if(!_this.id){url="/api/Multiple/add_subject";}
            // }
            // if(_this.type==3 || _this.type==4){
            //   url="/api/Completion/edit_subject";
            //   if(!_this.id){url="/api/Completion/add_subject";}
            // }

            _this.axios.post(url, _data).then(function(data) {
              if(data){
                _this.tip_show('操作成功','success');
                _this.$router.go(-1)
              }
              _this.is_ajax=false;
            }).catch(function(error) {
              _this.is_ajax=false
              console.log(error);
            })
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const _this=this;
      const ids = this.get_checked_ids();
      let indexs= this.get_checked_indexs();
      this.$confirm('是否确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          if(ids.length>0){
            _this.axios.post('/api/subject.AnswerOperate/del_answer', {answer_ids:ids}).then(function(data) {
              if(data){
                for(let i=indexs.length-1;i>=0;i--){
                  _this.answers.splice(indexs[i],1);
                  // _this.form.have_answer=_this.answers.length>0?1:'';
                  _this.$forceUpdate();
                }
              }
            }).catch(function(error) {
              console.log(error);
            })
          }else{
            for(let i=indexs.length-1;i>=0;i--){
              _this.answers.splice(indexs[i],1);
              // _this.form.have_answer=_this.answers.length>0?1:'';
              _this.$forceUpdate();
            }
          }
        })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.zhuan_span{background:#E4EAF0; color: #1F2329; line-height: 28px; font-size: 16px; padding: 0 12px; display: inline-block; border-radius: 28px;}
.subject_items .item{padding: 12px 20px; line-height: 22px; font-size: 18px; margin-bottom: 8px; background: #F4F7FA;}
.color_green{color: #3CB53C;}
.sub_op_btn a{display: flex; align-items: center; font-size: 16px;}
.sub_op_btn a img{margin-right: 4px;}

.tiankong{background: #F4F7FA;font-size: 15px; min-height: 56px; padding-right: 30px; border: 1px solid #DCDFE6;border-radius: 4px; padding: 10px 15px; line-height: 1.5; outline: none;}
.tiankong:focus{background: #fff;}


.right_set{background: #F9FAFC;  width: 282px; margin-top: 20px;}
.right_set .tt{color: #828696; line-height: 20px; padding-top: 16px;}
.right_set .setitem{margin: 8px 0;background: #F4F7FA; border-radius: 4px; padding: 3px; border: 1px solid #F0F2F5; padding-left: 12px;}
.right_set .setitem a{display: block; line-height: 32px; color: #004EA2; background: #D9E4EF; padding: 0 8px; border-radius: 4px;}
.line{height: 1px; background: #DFE6EE; margin-top: 20px; margin-bottom: 10px;}

</style>
